<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.io.CharArrayReader"%>
<%@page import="java.io.Reader"%>
<%@page import="oracle.sql.CLOB"%>
<%@page import="java.io.Writer"%>
<%@page import="java.sql.Clob"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		String str = request.getParameter("content");
	System.out.println(str.length());
		String driver = "oracle.jdbc.driver.OracleDriver";
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
		String db_user = "semi";
		String db_pwd = "semi";
		Connection con; 
		PreparedStatement psmt;
		ResultSet rs;
		String sql1="update test set content=empty_clob() where no=2";
		String sql2="select content from test where no=2 for update";
		int cnt1=0;
		try {
			Class.forName(driver).newInstance();
			con = DriverManager.getConnection(url, db_user, db_pwd);
			System.out.println("DB접속 성공");
			con.setAutoCommit(false);
			psmt = con.prepareStatement(sql1);
			cnt1=psmt.executeUpdate();
			psmt.close();
			psmt = con.prepareStatement(sql2);
			rs = psmt.executeQuery();
			if(rs.next()){
				Clob clob= rs.getClob("content");
				Writer writer = ((CLOB)clob).getCharacterOutputStream();
				Reader src = new CharArrayReader(str.toCharArray());
				char[] buffer = new char[1024];
				int read=0;
				while((read = src.read(buffer,0,1024))!=-1){
					writer.write(buffer,0,read);
				}
				src.close();
				writer.close();
			}
			con.commit();
			con.setAutoCommit(true);
			rs.close();
			psmt.close();
			System.out.println("수정끝");
			
			
			rs.close();
			psmt.close();
			con.close();
			%>
			<textarea rows="" cols=""><%=str %></textarea>
			<%
		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
</body>
</html>